package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlChatUsers entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlChatUsers
 * @author MyEclipse Persistence Tools
 */

public class MdlChatUsersDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlChatUsersDAO.class);
	// property constants
	public static final String CHATID = "chatid";
	public static final String USERID = "userid";
	public static final String GROUPID = "groupid";
	public static final String VERSION = "version";
	public static final String IP = "ip";
	public static final String FIRSTPING = "firstping";
	public static final String LASTPING = "lastping";
	public static final String LASTMESSAGEPING = "lastmessageping";
	public static final String SID = "sid";
	public static final String COURSE = "course";
	public static final String LANG = "lang";

	public void save(MdlChatUsers transientInstance) {
		log.debug("saving MdlChatUsers instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlChatUsers persistentInstance) {
		log.debug("deleting MdlChatUsers instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlChatUsers findById(java.lang.Long id) {
		log.debug("getting MdlChatUsers instance with id: " + id);
		try {
			MdlChatUsers instance = (MdlChatUsers) getSession().get(
					"idv.loveloser.dao.MdlChatUsers", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlChatUsers instance) {
		log.debug("finding MdlChatUsers instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlChatUsers")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlChatUsers instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlChatUsers as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByChatid(Object chatid) {
		return findByProperty(CHATID, chatid);
	}

	public List findByUserid(Object userid) {
		return findByProperty(USERID, userid);
	}

	public List findByGroupid(Object groupid) {
		return findByProperty(GROUPID, groupid);
	}

	public List findByVersion(Object version) {
		return findByProperty(VERSION, version);
	}

	public List findByIp(Object ip) {
		return findByProperty(IP, ip);
	}

	public List findByFirstping(Object firstping) {
		return findByProperty(FIRSTPING, firstping);
	}

	public List findByLastping(Object lastping) {
		return findByProperty(LASTPING, lastping);
	}

	public List findByLastmessageping(Object lastmessageping) {
		return findByProperty(LASTMESSAGEPING, lastmessageping);
	}

	public List findBySid(Object sid) {
		return findByProperty(SID, sid);
	}

	public List findByCourse(Object course) {
		return findByProperty(COURSE, course);
	}

	public List findByLang(Object lang) {
		return findByProperty(LANG, lang);
	}

	public List findAll() {
		log.debug("finding all MdlChatUsers instances");
		try {
			String queryString = "from MdlChatUsers";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlChatUsers merge(MdlChatUsers detachedInstance) {
		log.debug("merging MdlChatUsers instance");
		try {
			MdlChatUsers result = (MdlChatUsers) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlChatUsers instance) {
		log.debug("attaching dirty MdlChatUsers instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlChatUsers instance) {
		log.debug("attaching clean MdlChatUsers instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}